from django.db import models
from config.choices import SHOW_CHOICES, COMMON_CHOICES
from utils.models import CoreModel


# Create your models here.


class DataColumns(CoreModel):
    name = models.CharField(max_length=40, verbose_name="管理名称", help_text="管理名称")
    path = models.CharField(max_length=40, verbose_name="路由", help_text="路由")
    title = models.CharField(max_length=40, verbose_name="字段名", help_text="字段名")
    dataIndex = models.CharField(max_length=40, verbose_name="字段索引", help_text="字段索引")
    show = models.BooleanField(choices=SHOW_CHOICES, default=True, verbose_name="字段是否显示",
                               help_text="字段是否显示")
    align = models.CharField(max_length=40, default="center", verbose_name="字段布局", help_text="字段布局")
    width = models.SmallIntegerField(default=100, verbose_name="字段宽度", help_text="字段宽度")
    common = models.BooleanField(choices=COMMON_CHOICES, default=True, verbose_name="是否为公共字段",
                                 help_text="是否为公共字段")

    class Meta:
        db_table = 'data_columns'
        verbose_name = '数据字段表'
        verbose_name_plural = verbose_name
        ordering = ('sort',)


class Dict(CoreModel):
    name = models.CharField(max_length=50, null=False, unique=True, verbose_name="字典名称", help_text="字典名称")
    code = models.CharField(max_length=50, null=False, unique=True, verbose_name="字典编码", help_text="字典编码")

    class Meta:
        db_table = "data_dict"
        verbose_name = "字典表"
        verbose_name_plural = verbose_name
        ordering = ('-create_time',)


class DictType(CoreModel):
    name = models.CharField(null=False, max_length=150, verbose_name="字典类型名称", help_text="字典类型称")
    value = models.CharField(null=False, max_length=150, verbose_name="字典类型值", help_text="字典类型值")
    dicts = models.ForeignKey(to='Dict', on_delete=models.CASCADE, verbose_name="字典ID", null=True, blank=True,
                              db_constraint=False, help_text="字典ID")

    class Meta:
        db_table = "data_dictType"
        verbose_name = "字典类型表"
        verbose_name_plural = verbose_name
        ordering = ('-create_time',)
